package com.qf.fanwang.dao.impl;

import com.qf.fanwang.dao.UDao;
import com.qf.fanwang.pojo.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;

import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class UDaoImpl implements UDao {
private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<User> select() {
        List<User> list = jdbcTemplate.query("select  uid uid,username uname,password upass,email uemail,gender ugender,flag  uflag,role urole,code ucode from user", new BeanPropertyRowMapper<User>(User.class));
        return list;
    }

    @Override
    public int uadd(User user) {
        int update = jdbcTemplate.update("insert into user values(null,?,?,?,?,?,?,?)", user.getUname(), user.getUpass(), user.getUemail(), user.getUgender(), user.getUflag(), user.getUrole(), user.getUcode());
        return update;
    }

    @Override
    public int update(int id) {
        int update = jdbcTemplate.update("delete from user where uid=?", id);
        return update;
    }
}
